package util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import model.Populacao;

public class Main{

	public static void main(String a[]) throws IOException, InterruptedException{		
		long start = System.currentTimeMillis();
		System.out.println("Start: ");
		
		int numPontos = 20;
		int numAmostras = 5;
		
		long raiz = -537998;
		double m = 0.005;
		double u = 0.005;
		int D = 100;
		int Nd = 300;
		int numciclos = 3*D*Nd;
		
		long[] media = new long[numPontos+1];
		long[] parcial;
		
		for(int i = 1; i<=numAmostras; i++){
			Populacao p = new Populacao(raiz+1, m, u, D, Nd);
			p.simular(numciclos,numPontos);
			parcial = p.getHistoricoDiversidade();
			
			for(int j=0; j<parcial.length;j++){
				media[j] += parcial[j];
			}
			System.out.println("Andamento..." + (i*100)/numAmostras + "% ");
		}
		
		for(int j=0; j<media.length;j++){
			media[j] /= numAmostras;
		}
		
		PrintWriter saida = new PrintWriter(new FileWriter(new File("padroes.dat"),true));
		
		String novoPadrao = "";
		novoPadrao = novoPadrao.concat(m+","+u+","+D+","+Nd);
		for(int j=0; j<media.length;j++){
			novoPadrao = novoPadrao.concat(","+media[j]);
		}
		
		saida.println("\n");
		saida.append(novoPadrao);
		saida.close();
		
		System.out.printf("Duration: %.2f minutos.",((double)(System.currentTimeMillis() - start)/60000));

		
		
		//		long start = System.currentTimeMillis();
//		System.out.println("Start: ");
//		
//		Simulador s = new Simulador(-5378, 100, 1000, 0.001, 0.0001);
//		s.start(5, 5000, 20);
//		
//		System.out.printf("Duration: %.2f minutos.",((double)(System.currentTimeMillis() - start)/60000));
	}
}       